﻿Imports Microsoft.AspNet.Identity
Imports Microsoft.AspNet.Identity.EntityFramework
Imports Microsoft.AspNet.Identity.Owin
Imports System
Imports System.Linq
Imports System.Web
Imports System.Web.UI

Partial Public Class Register
    Inherits Page
    Protected Sub CreateUser_Click(sender As Object, e As EventArgs)
        Dim userName As String = UserNameCtrl.Text
        Dim store = New AuthenticationIdentityManager(New IdentityStore())
        Dim u As New User(userName) With {
          .UserName = userName
        }
        
        Dim result As IdentityResult = store.Users.CreateLocalUser(u, Password.Text)
        If result.Success Then
            store.Authentication.SignIn(Context.GetOwinContext().Authentication, u.Id, isPersistent:=False)
            OpenAuthProviders.RedirectToReturnUrl(Request.QueryString("ReturnUrl"), Response)
        Else
            ErrorMessage.Text = result.Errors.FirstOrDefault()
        End If
    End Sub
End Class
